#include <iostream>

#include "stdafx.h"

#include "project.h"
#include "projecteventbus.h"
#include "projectevent.h"
#include "projectui.h"
CWinApp theApp;
Project::Project()
    : eventhandler(ProjectEventHandler::self())
{
}

Project::~Project()
{
    delete eventhandler;
    delete ui;
}

void Project::Initialize( IPluginFacade* Cine )
{
    facade = Cine;
    ui = new ProjectUI;
    ui->init( Cine );
}

void Project::Activate()
{
    std::cerr << "project::activate\n";
    ui->attach( eventhandler );

    facade->AttachListener( Events::Command , eventhandler );
    facade->AttachListener( Events::UpdateCommandUI , eventhandler );
}

void Project::Deactivate()
{
    std::cerr << "project::deactivate\n";

    facade->ReleaseListener( eventhandler );
    ui->remove();
}

bool Project::HandleEvent( Events::Event* event )
{
    return eventhandler->HandleEvent( event );
}

// the class factories
extern "C" IPlugin* CreatePluginObject() { return new Project; }

extern "C" void DestroyPluginObject( IPlugin* p ) { delete (Project*)p; }

extern "C" const char* GetPluginName() { return "Project Framework Plugin\0"; }

extern "C" int GetPluginVersion() { return -1; }/// NOTE: hmm.. unstable ATM

